
//src/commands/createComponent.ts
//创建 Vue 组件生成逻辑
import fs from "fs";
import path from "path";
const clc = require('cli-color');

export function createComponent(name: string) {
  const componentDir = path.join(process.cwd(), "src/components", name);
  if (fs.existsSync(componentDir)) {
    console.log(clc.red("组件已存在！"));
    return;
  }
  fs.mkdirSync(componentDir, { recursive: true });

  const componentTemplate = `
<script setup lang="ts">
 import { ref } from "vue";
 const msg = ref("R");
</script>

<template>
  <div class="my-${name}">{{ msg }}</div>
</template>

<style scoped>
.my-${name} {
  color: blue;
}
</style>
`;
  fs.writeFileSync(path.join(componentDir, `${name}.vue`), componentTemplate);
  console.log(clc.green(`组件 ${name} 创建成功！`));
}